/**
 * 
 */
package org.shark.jdbcTemplateTool.utils;

import java.util.List;

import org.shark.jdbcTemplateTool.utils.cache.CacheBuilder;
import org.shark.jdbcTemplateTool.utils.cache.ICache;

import net.sf.ehcache.CacheManager;

/**
 * @author lenovo
 * @description
 * @date 2016年8月15日
 */
public class CacheUtil {
	
	private CacheManager cacheManager;

	private static class SingletonClass {
		private static CacheUtil newInstant = new CacheUtil();
	}

	
	public static CacheUtil getInstant() {
		return SingletonClass.newInstant;
	}
	
	private ICache getCache() {
		return CacheBuilder.build(cacheManager);
	}

	
	public void put(String cacheName, Object key, Object value) {
		getCache().put(cacheName, key, value);
	}
	
	public <T> T get(String cacheName, Object key) {
		return getCache().get(cacheName, key);
	}
	
	@SuppressWarnings("rawtypes")
	public List getKeys(String cacheName) {
		return getCache().getKeys(cacheName);
	}
	
	public void remove(String cacheName, Object key) {
		getCache().remove(cacheName, key);
	}
	
	public void removeAll(String cacheName) {
		getCache().removeAll(cacheName);
	}
	
	public boolean containKey(String cacheName, String key) {
		if (getCache().containKey(cacheName)) {
			return getCache().get(cacheName, key) != null;
		}
		return false;
	}

	public CacheManager getCacheManager() {
		return cacheManager;
	}

	public void setCacheManager(CacheManager cacheManager) {
		this.cacheManager = cacheManager;
	}
}
